package com.cheng.im.service.friendship.controller;

import com.cheng.im.service.common.model.SyncReq;
import com.cheng.im.service.common.model.SyncResp;
import com.cheng.im.service.common.resp.CommonResult;
import com.cheng.im.service.friendship.service.ImFriendshipService;
import com.cheng.im.service.frienship.domain.ImFriendship;
import com.cheng.im.service.frienship.model.req.*;
import com.cheng.im.service.frienship.model.resp.CheckFriendShipResp;
import com.cheng.im.service.frienship.model.resp.ImportFriendShipResp;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiModelProperty;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@Api(tags = "好友关系")
@RestController
@RequestMapping("/v1/friendship")
public class ImFriendshipController {

    @Resource
    ImFriendshipService imFriendShipService;

    /**
     * 批量导入好友
     * @param req
     * @return
     */
    @ApiOperation(value = "批量导入", notes = "批量导入好友关系")
    @PostMapping("/importFriendShip")
    public CommonResult<ImportFriendShipResp> importFriendShip(@RequestBody @Validated ImporFriendShipReq req){
        return imFriendShipService.importFriendShip(req);
    }

    /**
     * 添加好友申请
     * @param req
     * @return
     */
    @PostMapping("/addFriend")
    @ApiOperation(value = "添加好友关系", notes = "与批量导入好友关系的区别就是，这是单条导入的")
    public CommonResult addFriend(@RequestBody @Validated AddFriendReq req){
        return imFriendShipService.addFriend(req);
    }

    /**
     * 更改好友信息，比如备注
     * @param req
     * @return
     */
    @PutMapping("/updateFriend")
    @ApiOperation(value = "更新好友关系", notes = "更改好友信息，比如备注")
    public CommonResult updateFriend(@RequestBody @Validated UpdateFriendReq req){
        return imFriendShipService.updateFriend(req);
    }

    /**
     * 删除好友
     * @param req
     * @return
     */
    @DeleteMapping("/deleteFriend")
    @ApiOperation(value = "删除好友", notes = "")
    public CommonResult deleteFriend(@RequestBody @Validated DeleteFriendReq req){
        return imFriendShipService.deleteFriend(req);
    }

    /**
     * 删除所有好友
     * @param req
     * @return
     */
    @DeleteMapping("/deleteAllFriend")
    @ApiOperation(value = "删除所有好友", notes = "")
    public CommonResult deleteAllFriend(@RequestBody @Validated DeleteFriendReq req){
        return imFriendShipService.deleteAllFriend(req);
    }

    /**
     * 获取所有好友
     * @param req
     * @return
     */
    @PostMapping("/getAllFriendShip")
    @ApiOperation(value = "获取所有好友", notes = "")
    public CommonResult<List<ImFriendship>> getAllFriendShip(@RequestBody @Validated GetAllFriendShipReq req){
        return imFriendShipService.getAllFriendShip(req);
    }

    /**
     * 获取好友之间关系
     * @param req
     * @return
     */
    @PostMapping("/getRelation")
    @ApiOperation(value = "好友关系", notes = "")
    public CommonResult<ImFriendship> getRelation(@RequestBody @Validated GetRelationReq req){
        return imFriendShipService.getRelation(req);
    }

    /**
     * 批量检查好友之间关系
     * @param req
     * @return
     */
    @PostMapping("/checkFriend")
    @ApiOperation(value = "检查好友关系", notes = "")
    public CommonResult<List<CheckFriendShipResp>> checkFriend(@RequestBody @Validated CheckFriendShipReq req){
        return imFriendShipService.checkFriendship(req);
    }

    /**
     * 添加黑名单
     * @param req
     * @return
     */
    @PostMapping("/addBlack")
    @ApiOperation(value = "拉入黑名单", notes = "")
    public CommonResult addBlack(@RequestBody @Validated AddFriendShipBlackReq req){
        return imFriendShipService.addBlack(req);
    }

    /**
     * 移除黑名单
     * @param req
     * @return
     */
    @ApiOperation(value = "移出黑名单", notes = "")
    @DeleteMapping("/deleteBlack")
    public CommonResult deleteBlack(@RequestBody @Validated DeleteBlackReq req){
        return imFriendShipService.deleteBlack(req);
    }

    /**
     * 检查黑名单
     * @param req
     * @return
     */
    @ApiOperation(value = "检查黑名单", notes = "")
    @PostMapping("/checkBlack")
    public CommonResult<List<CheckFriendShipResp>> checkBlack(@RequestBody @Validated CheckFriendShipReq req){
        return imFriendShipService.checkBlack(req);
    }


    @ApiOperation(value = "同步好友列表", notes = "")
    @PostMapping("/syncFriendshipList")
    public CommonResult<SyncResp<ImFriendship>> syncFriendshipList(@RequestBody @Validated SyncReq req){
        return imFriendShipService.syncFriendshipList(req);
    }
}
